from django import template
from django.utils.safestring import mark_safe

register = template.Library()

@register.filter(name='pretty_user')
def pretty_user(value, linkify=1):
    """
    Prima user profile i pravi od njega link ka njegovom profilu sa tekstom imena i prezimena
    """
    if linkify != 0:
        url = "/mdcs/user/%d/" % value.id
        if linkify == 2:
            url = "http://sport.mdcs.rs" + url
        if value.user.is_active:
            if value.is_mdcs:
                css_class = "user"
            else:
                css_class = "user_notmdcs"
        else:
            if value.is_mdcs:
                css_class = "user_notactive"
            else:
                css_class = "user_notmdcs_notactive"
        return mark_safe(
            "<a class=\"%s\" href=\"%s\">%s %s</a>" %
                (css_class, url, value.user.first_name, value.user.last_name)
        )
    else:
        return mark_safe("%s %s" % (value.user.first_name, value.user.last_name))

@register.filter(name='pretty_users')
def pretty_users(value, linkify=1):
    """
    Prima vise user profile-a i pravi od njih listu odvojenu zarezima sa linkovima ka profilima sa tekstom imena i prezimena
    """
    first = True
    result = ""
    for user in value.all():
        if not first:
            result += ","
        result += pretty_user(user, linkify)
        first = False
    return result